Page({

  data: {
    tables: [],
    detailAddress: [],
    userID: null
  },

  onLoad: function () {
    let that = this;
    wx.getStorage({
      key: 'userID',
      success(res) {
        that.setData({
          userID: res.data
        }) 
      }
    });
    let userId = this.data.userID;
    if (userId == null) {
      userId = getApp().globalData.userID
    }
    console.log(userId);
    wx.request({
      url: 'https://localhost:80/address/queryAllId/' + userId,
      header: {
        'content-type': 'application/json'
      },
      success (res) {
        console.log(res);       
        let Detail = [];
        for (let i = 0; i < res.data.length; i++)
        {
          Detail[i] = res.data[i].addrProvince + res.data[i].addrCity + res.data[i].addrArea + res.data[i].addrCommuity + res.data[i].addrDetail
        }
        that.setData({
          tables: res.data,
          detailAddress: Detail
        })       
        console.log('ok');
        console.log(that.data.tables);      
      }
    });
  },
  
  skipaddress (e) {
    console.log(e.target.dataset.index);
    let number = e.target.dataset.index;
    console.log(this.data.tables[number]);
    wx.navigateTo({
      url: "../editaddress/editaddress?data=" + JSON.stringify(this.data.tables[number])
    })
  },

  onUnload: function () {
    let num = getCurrentPages().length;
    console.log(num);
    console.log('==============================================================');
    if (num >= 3) {
      wx.navigateBack({
        delta: num
      })
    } else {
      wx.switchTab({
        url: '../person/person'
      })
    }
  }
})

